package top.lyc829.zzl_android.ui.base_detail.show_map;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;

import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.AMapOptions;
import com.amap.api.maps2d.CameraUpdate;
import com.amap.api.maps2d.CameraUpdateFactory;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.model.CameraPosition;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.maps2d.model.Marker;
import com.amap.api.maps2d.model.MarkerOptions;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;

import top.lyc829.zzl_android.R;
import top.lyc829.zzl_android.logic.util.Utils;

public class ShowMapActivity extends AppCompatActivity {

//    private LatLng centerSHpoint = new LatLng(31.238068, 121.501654);// 上海市经纬度
    private LatLng centerSHpoint;
    AMap aMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_map);

//        aOptions.camera(new CameraPosition(centerSHpoint, 10f, 0, 0));
        double lat = getIntent().getDoubleExtra("lat", 0F);
        double lng = getIntent().getDoubleExtra("lng", 0F);

        centerSHpoint = new LatLng(lat, lng);

        MapView mapView = (MapView) findViewById(R.id.map);

        mapView.onCreate(savedInstanceState);// 此方法必须重写

        aMap = mapView.getMap();

        CameraPosition position = new CameraPosition(centerSHpoint, 10f, 0, 0);
        CameraUpdate update = CameraUpdateFactory.newCameraPosition(position);
        aMap.moveCamera(update);

        drawMarkers();

    }

    private void drawMarkers() {
        MarkerOptions options = new MarkerOptions()
                .position(centerSHpoint)
                .draggable(true);
        Marker marker = aMap.addMarker(options);
        marker.showInfoWindow();

    }

//    public static String sHA1(Context context){
//        try {
//            PackageInfo info = context.getPackageManager().getPackageInfo(
//                    context.getPackageName(), PackageManager.GET_SIGNATURES);
//            byte[] cert = info.signatures[0].toByteArray();
//            MessageDigest md = MessageDigest.getInstance("SHA1");
//            byte[] publicKey = md.digest(cert);
//            StringBuffer hexString = new StringBuffer();
//            for (int i = 0; i < publicKey.length; i++) {
//                String appendString = Integer.toHexString(0xFF & publicKey[i])
//                        .toUpperCase(Locale.US);
//                if (appendString.length() == 1)
//                    hexString.append("0");
//                hexString.append(appendString);
//                hexString.append(":");
//            }
//            String result = hexString.toString();
//            return result.substring(0, result.length()-1);
//        } catch (PackageManager.NameNotFoundException e) {
//            e.printStackTrace();
//        } catch (NoSuchAlgorithmException e) {
//            e.printStackTrace();
//        }
//        return null;
//    }

}